/**
 * Software License, Version 1.0
 *
 * Copyright 2003 The Trustees of Indiana University.  All rights reserved.
 *
 *
 *Redistribution and use in source and binary forms, with or without
 *modification, are permitted provided that the following conditions are met:
 *
 *1) All redistributions of source code must retain the above copyright notice,
 * the list of authors in the original source code, this list of conditions and
 * the disclaimer listed in this license;
 *2) All redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the disclaimer listed in this license in
 * the documentation and/or other materials provided with the distribution;
 *3) Any documentation included with all redistributions must include the
 * following acknowledgement:
 *
 *"This product includes software developed by the Community Grids Lab. For
 * further information contact the Community Grids Lab at
 * http://communitygrids.iu.edu/."
 *
 * Alternatively, this acknowledgement may appear in the software itself, and
 * wherever such third-party acknowledgments normally appear.
 *
 *4) The name Indiana University or Community Grids Lab or NaradaBrokering,
 * shall not be used to endorse or promote products derived from this software
 * without prior written permission from Indiana University.  For written
 * permission, please contact the Advanced Research and Technology Institute
 * ("ARTI") at 351 West 10th Street, Indianapolis, Indiana 46202.
 *5) Products derived from this software may not be called NaradaBrokering,
 * nor may Indiana University or Community Grids Lab or NaradaBrokering appear
 * in their name, without prior written permission of ARTI.
 *
 *
 * Indiana University provides no reassurances that the source code provided
 * does not infringe the patent or any other intellectual property rights of
 * any other entity.  Indiana University disclaims any liability to any
 * recipient for claims brought by any other entity based on infringement of
 * intellectual property rights or otherwise.
 *
 *LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH NO
 *WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA UNIVERSITY GIVES
 *NO WARRANTIES AND MAKES NO REPRESENTATION THAT SOFTWARE IS FREE OF
 *INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER PROPRIETARY RIGHTS.
 *INDIANA UNIVERSITY MAKES NO WARRANTIES THAT SOFTWARE IS FREE FROM "BUGS",
 *"VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", OR OTHER HARMFUL CODE.
 *LICENSEE ASSUMES THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR
 *ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION
 *GENERATED USING SOFTWARE.
 */
package cgl.narada.service.storage;

import java.util.LinkedList;

import cgl.narada.event.TemplateInfo;
import cgl.narada.matching.Profile;
import cgl.narada.service.ServiceException;
import cgl.narada.service.reliable.CompanionDbInfo;

/** Provides a host of storage related operations that are important for
 ensuring reliable delivery

 @author Shrideep Pallickara
 $Date$
 $Revision$
 */

public interface StorageService {

    public void storeProfile(int templateId, Profile profile) throws
            ServiceException;

    public void removeProfile(int templateId, Profile profile) throws
            ServiceException;

    /** Stores a registered entity */
    public void storeRegisteredEntity(int entityId) throws ServiceException;

    /** Removes a registered entity. This method should also remove the entity
     from any profiles that it was subscribed to and and templateId to which
     it was registered */
    public void removeRegisteredEntity(int entityId) throws ServiceException;

    public void storeTemplate(TemplateInfo templateInfo) throws
            ServiceException;

    public void removeTemplateManagement(int templateId) throws
            ServiceException;

    public void storeEntityForTemplate(int entityId, int templateId) throws
            ServiceException;

    /** Deregister's an entity from a managed template */
    public void removeEntityFromTemplate(int entityId, int templateId) throws
            ServiceException;

    /** Returns a list of registered entities */
    public int[] getListOfRegisteredEntities() throws ServiceException;

    /** Returns a list of registered entities to a given template */
    public int[] getListOfRegisteredEntities(int templateId) throws
            ServiceException;

    /** Returns a list of profiles registered to a given template */
    public Profile[] getListOfRegisteredProfiles(int templateId) throws
            ServiceException;

    /**  Returns a array containing the list of managed templates */
    public TemplateInfo[] getListOfManagedTemplates() throws ServiceException;

    /** This method should not return unless  the event has been written to
     stable storage */
//    public void store(InventoryEvent inventoryEvent,
//                      SequenceDestinations sequenceDestinations) throws
//            ServiceException;

    public void store(CompanionDbInfo companionDbInfo,
                      InventoryEvent inventoryEvent,
                      SequenceDestinations sequenceDestinations) throws
            ServiceException;

    /** Upon receipt of a NAK request we need to retrieve the inventory event
     that corresponds to  */
    public InventoryEvent getStoredEvent(long sequenceNumber) throws
            ServiceException;

    /** Process the acknowledgement of an event's receipt by an entity */
    public void processAcknowledgement(long sequenceNumber, int entityId) throws
            ServiceException;

    /** This method checks to see if the sequences in the arguments belong to the
     specified template. The return argument of this method, is the list of
     sequences that did not belong to the template in question. If the return
     value is null it implies that all the sequences passed as an argument to
     this method did indeed belong to the template in question */
    public long[] checkIfSequencesBelongToTemplate(int templateId,
            long[] sequences) throws ServiceException;

    public LinkedList retrieveSequencesAndTimestamps(int templateId) throws
            ServiceException;

    public LinkedList retrieveSequencesAndTimestamps(long startingTimestamp,
            long endingTimestamp, int templateId) throws ServiceException;

    public long retrieveTimestamp(int templateId, long sequenceNumber) throws
            ServiceException;

    public LinkedList retrieveSequencesAndTimestampsStartingAt(
            long startingSequenceNumber, long endingTimestamp, int templateId) throws
            ServiceException;

    public LinkedList retrieveSequencesByTimestamps(long startingTimestamp,
            long endingTimestamp, int templateId) throws ServiceException;

    public long getTimestamp(long sequnceNumber, int templateId) throws
            ServiceException;

    /** Between the sequence range specified, this method returns all sequences
     which belong to the specified template. The maxOccurs variable controls
     the maximum number of sequences that needs to be returned by this
     method.  */
    public long[] retrieveSequences(long startingAt, long endingAt,
                                    int templateId, int maxOccurs) throws
            ServiceException;

    /** Retrieves a list of missed sequences between the specified range of
     sequence numbers. This method will return a null if there are indeed
     no missed sequences */
    public long[] retrieveMissedSequences(long startingAt, long endingAt,
                                          int templateId, int entityId) throws
            ServiceException;

    /** Advance the sync point associated with an entity */
    public void advanceSyncpoint(long syncpoint, int templateId, int entityId) throws
            ServiceException;

    /** Get the syncpoint associated with an entity */
    public long getSyncpoint(int templateId, int entityId) throws
            ServiceException;

    /** Advance the catenation associated with an entity */
    public void advanceCatenation(int catenation, int templateId, int entityId) throws
            ServiceException;

    /** Get the catenation associated with an entity */
    public int getCatenation(int templateId, int entityId) throws
            ServiceException;

    /** Returns the sequence number last assigned by the reliable delivery
     service*/
    public long getSequenceNumberLastAssigned() throws ServiceException;

    /** Returns the sequence number last assigned by the reliable delivery
     service for a given templateId */
    public long getSequenceNumberLastAssigned(int templateId) throws
            ServiceException;

    public LinkedList retrieveMinimumSequeceNumberAndTimestamp(int temlateId) throws
            ServiceException;

    public LinkedList retrieveMaximumSequeceNumberAndTimestamp(int temlateId) throws
            ServiceException;
}
